home *** CD-ROM | disk | FTP | other *** search
- unit FMain;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ShlObj, Menus, StdCtrls, ComCtrls,
- UPTShellUtils, UPTFrame, UPTTreeList, UPTShellControls;
-
- type
- TFrmMain = class(TForm)
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- Exit1: TMenuItem;
- PTShellTree1: TPTShellTree;
- PTFrame1: TPTFrame;
- Label1: TLabel;
- CompLabel: TPTGroup;
- Label2: TLabel;
- procedure FormCreate(Sender: TObject);
- procedure Exit1Click(Sender: TObject);
- procedure PTShellTree1Change(Sender: TObject; Node: TTreeNode);
- private
- FComputerIndex: Integer;
- procedure SetFrameText( aName: String );
- public
- { Public declarations }
- end;
-
- var
- FrmMain: TFrmMain;
-
- implementation
-
- {$R *.DFM}
-
- {
- The technique used to determine which nodes are "Computer" nodes is find which image is
- used for computers and simple check a node's image against that value. It should be
- possible to use the SHGetDataFromIDList function to check what type a node is, but
- that function seems very unreliable.
- }
- procedure TFrmMain.FormCreate(Sender: TObject);
- var sz: array[0..MAX_COMPUTERNAME_LENGTH] of Char;
- siz: DWORD;
- begin
- try
- siz := Sizeof(sz);
- Windows.GetComputerName( @sz[0], siz );
- if Length(sz) <= 0 then
- raise Exception.Create( 'This computer is not present on the network.' );
- FComputerIndex := ShellGetIconIndexFromPath('\\'+sz,0);
- except
- on e: Exception do
- begin
- Application.ShowMainForm := FALSE;
- Application.HandleException(e);
- Application.Terminate;
- end;
- end;
- end;
-
- procedure TFrmMain.PTShellTree1Change(Sender: TObject; Node: TTreeNode);
- begin
- if Node.ImageIndex = FComputerIndex then
- SetFrameText( Node.Text )
- else
- SetFrameText( '' );
- end;
-
- procedure TFrmMain.SetFrameText( aName: String );
- begin
- if aName='' then
- begin
- CompLabel.Caption := '<Not a computer>';
- CompLabel.Color := clRed;
- end
- else
- begin
- CompLabel.Caption := aName;
- CompLabel.Color := clGreen;
- end;
- end;
-
- procedure TFrmMain.Exit1Click(Sender: TObject);
- begin
- Close;
- end;
-
- end.
-
-